package com.gimi.cloud.bbp.manage.controller.log;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.common.annotation.RequestLog;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.enums.ServiceNameConstants;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.log.LogMasterLoginDTO;
import com.gimi.cloud.bbp.manage.service.log.LogMasterLoginService;
import com.github.pagehelper.PageInfo;

/**
 *  管理员登录日志
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-01-27
 **/
@RestController
@RequestMapping("/log/masterLogin")
public class LogMasterLoginController {
    private static final Logger logger  = LoggerFactory.getLogger(LogMasterLoginController.class);
    private LogMasterLoginService logMasterLoginService;

    @Autowired
    public LogMasterLoginController(LogMasterLoginService logMasterLoginService) {
        this.logMasterLoginService = logMasterLoginService;
    }

    /**
     * 获取操作员登录日志
     * @param request
     * @param response
     * @param loginDTO
     * @throws Exception
     */
    @RequestMapping("/list")
    @RequestLog(title="登录日志",type="LogMasterLoginController.list",isLogParam=true,isLogResult = true)
    @ResponseBody
    public Response list(HttpServletRequest request, HttpServletResponse response,@RequestBody LogMasterLoginDTO loginDTO) throws Exception{
        Response resp = new Response();
        List<LogMasterLoginDTO> masters = logMasterLoginService.queryList(loginDTO,true);
        Map<String,Object> resData = new HashMap<>();
        PageInfo<LogMasterLoginDTO> pageInfo = new PageInfo<>(masters);
        resData.put(ServiceNameConstants.PAGEDATA_KEY,pageInfo);
        resp.setRes_data(resData);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        return resp;
    }

}
